﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using iLangl.Model;
using iLangl.Plugin;

namespace iLangl.Tests.SerializationFixture
{
	[TestClass]
	public class RegistrationPluginValidationTest : BaseTest
	{
		[TestMethod]
		public void RegistrationPluginValidation()
		{
			//Setup customer facade
			SwitchToCustomerSide();

			PluginRegistration pluginRegistration = GetTPPluginRegistration();

			PluginRegistrationRequestContext requestContext = new PluginRegistrationRequestContext();

			requestContext.SetContext(pluginRegistration);
			string serializedplugin = requestContext.GetContext().ToString();

			PluginRegistrationResponseContext responecontext = new PluginRegistrationResponseContext();
			responecontext.SetContext(serializedplugin);

			PluginRegistration pluginRegistration2 = (PluginRegistration)responecontext.GetContext();
			requestContext.SetContext(pluginRegistration2);
			string serializedplugin2 = requestContext.GetContext().ToString();

			Assert.AreEqual(serializedplugin, serializedplugin2);
		}

		public PluginRegistration GetTPPluginRegistration()
		{
			//Prepare Request
			PluginRegistration request = new PluginRegistration();

			request.PluginId = "B6C10D99-4E9A-4404-BEF5-B77C9EC7BE64";
			request.PluginName = "iLangl LanguageWire Plugin";
			request.PluginVersion = "1";
			request.SessionId = new PluginAuthenticationService().Authenticate("test");
			
			request.Company = CompanyValidationTest.GetCompany();
			request.Company.Id = TestSettings.LanguageWireCompanyId;
			request.Company.Name = "LanguageWire";

			List<Contact> contacts = new List<Contact>();
			Contact contact = new Contact();
			contact.Id = "4a893051-8263-4ec5-b344-23612404feaf";
			contact.Company = request.Company;
			contact.Email = "test1@test.email";
			contact.FirstName = "Thor A.";
			contact.LastName = "Angelo";
			contact.Phone = "(xxx)123-34-34";
			contact.Title = "CEO";

			contacts.Add(contact);

			contact = new Contact();
			contact.Id = "768C1256-70C8-432C-B99B-6937AA588BBF";
			contact.Company = request.Company;
			contact.Email = "aksel@test.email";
			contact.FirstName = "Aksel";
			contact.LastName = "Moller J.";
			contact.Phone = "(xxx)123-14-35";
			contact.Title = "Technical Director";
			contacts.Add(contact);

			request.Company.Contacts = contacts.ToArray();

			request.PrimaryContactId = request.Company.Contacts[0].Id;

			return request;
		}

		public PluginRegistration GetCustomerPluginRegistration()
		{
			//Prepare Request
			PluginRegistration request = new PluginRegistration();

			request.PluginId = "74002E79-C356-41A9-AA72-CC4127FF3945";
			request.PluginName = "iLangl Customer Plugin";
			request.PluginVersion = "1";
			request.SessionId = new PluginAuthenticationService().Authenticate("test");

			request.Company = CompanyValidationTest.GetCompany();

			Contact owner = new Contact();
			owner.Id = "6136B58A-FE4E-49B8-8048-6CEDBF99655A";
			owner.FirstName = "Sergey";
			owner.LastName = "Yuryev";
			owner.Email = "sergey.yuryev@gmail.com";
			owner.Phone = "8009109969";
			owner.Company = request.Company;

			request.Company.AddContact(owner);

			request.PrimaryContactId = owner.Id;

			

			return request;
		}
	}
}
